package com.apes.scm.masterdata.party.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.fileserver.File;
import com.apes.framework.util.ApesConst;
import com.apes.scm.account.res.model.Currency;
import com.apes.scm.account.tax.model.Tax;
import com.apes.scm.masterdata.area.model.Area;
import com.apes.scm.masterdata.area.model.Country;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 功能：公司入驻申请 信息
 *
 * @author LinWZ
 * @create 2019-10-24 11:23
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = CompanyEntry.CONST_TABLE_NAME)
public class CompanyEntry extends Model {
    public static final String CONST_TABLE_NAME = "mas_company_entry";

    @Id
    @Column(name = "id", length = 30)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "公司入驻申请",prefix="G",padding = 4)
    @Comment("单号")
    private String id;   //单号

    @Column(name = "code", length = 120)
    @Comment("显示编码")
    private String code;  //显示编码

    @OneToOne(optional = false)
    @JoinColumn(name = "PARTY_ID", referencedColumnName = "ID")
    @Comment("当事人编码")
    private Party party; //当事人

    @Name
    @Column(name = "name", nullable = false, length = 120)
    @Comment("当事人名称")
    private String name; //当事人名称

    @Column(name = "abbreviation", length = 32)
    @Comment("简称")
    private String abbreviation; //简称

    @Column(name = "bank", length = 200)
    @Comment("开户行")
    private String bank; //开户行

    @Column(name = "bank_account", length = 32)
    @Comment("银行帐号")
    private String bankAccount; //银行帐号

    @Column(name = "invoice_title", length = 200)
    @Comment("发票抬头")
    private String invoiceTitle;  //发票抬头

    @Column(name = "invoice_address", length = 256)
    @Comment("发票地址")
    private String invoiceAddress;  //发票地址

    @Column(name = "invoice_phone", length = 256)
    @Comment("发票电话")
    private String invoicePhone;  //发票电话

    @Column(name = "ORIGIN", length = 20)
    @Comment("外部ID")
    private String origin; //外部ID

    @Column(name = "settlement_center", columnDefinition = "number(1,0) default 0")
    @Comment("区域结算中心标记")
    private boolean settlementCenter = false;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_nature_id", referencedColumnName = "id")
    @Comment("公司性质编码")
    private Enumeration companyNature; //公司性质编码

    //注册地址（户籍地址）
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reg_country_id", referencedColumnName = "id")
    @Comment("注册地址.国家")
    private Country regCountry; //注册地址.国家

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reg_province_id", referencedColumnName = "id")
    @Comment("注册地址.省份")
    private Area regProvince; //注册地址.省份

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reg_city_id", referencedColumnName = "id")
    @Comment("注册地址.城市")
    private Area regCity; //注册地址.城市

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reg_county_id", referencedColumnName = "id")
    @Comment("注册地址.区县")
    private Area regCounty; //注册地址.区县

    @Column(name = "reg_address", length = 500)
    @Comment("注册地址.地址")
    private String regAddress; //注册地址.地址

    //办公地址
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "office_country_id", referencedColumnName = "id")
    @Comment("办公地点.国家")
    private Country officeCountry; //办公地点.国家

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "office_province_id", referencedColumnName = "id")
    @Comment("办公地点.省份")
    private Area officeProvince; //办公地点.省份

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "office_city_id", referencedColumnName = "id")
    @Comment("办公地点.城市")
    private Area officeCity; //办公地点.城市

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "office_county_id", referencedColumnName = "id")
    @Comment("办公地点.区县")
    private Area officeCounty; //办公地点.区县

    @Column(name = "office_address", length = 500)
    @Comment("办公地点.地址")
    private String officeAddress; //办公地点.地址

    @Column(name = "postal_code", length = 32)
    @Comment("邮政编码")
    private String postalCode; //邮政编码

    @Column(name = "uscc", length = 64)
    @Comment("统一社会信用代码")
    private String uscc; //统一社会信用代码（Unified social credit code）（营业执照号，税号，组织机构代码）

    @Column(name = "registered_capital", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("注册资金")
    private double registeredCapital;  //注册资金【万元】

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "operation", referencedColumnName = "id")
    @Comment("运营模式编码")
    private Enumeration operation; //运营模式

    /*-----------------------------------------------------
     * 公司信息
     *----------------------------------------------------*/
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "currency_id", referencedColumnName = "id")
    @Comment("币种编码")
    private Currency currency; //币种

    @Column(name = "max_invoice_value", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("最大发票金额")
    private double maxInvoiceValue = 0.0;  //最大发票金额

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "tax_id", referencedColumnName = "id")
    @Comment("销项税率编码")
    private Tax tax; //销项税率

    /*-----------------------------------------------------
     * 供应商信息
     *----------------------------------------------------*/
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "supplier_level", referencedColumnName = "id")
    @Comment("供应商级别编码")
    private Enumeration supplierLevel; //供应商级别(supplierLevel)(0:A级;1:B级;2:C级;3:D级;4:E级)
//    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
//    private boolean valid = true; //急件供应商标记
//    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
//    private boolean valid = true; //售后供应商标记

    /*-----------------------------------------------------
     * 客户信息
     *----------------------------------------------------*/
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "customer_group", referencedColumnName = "id")
    @Comment("客户组编码")
    private Enumeration customerGroup; //客户组

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "customer_category", referencedColumnName = "id")
    @Comment("客户类别编码")
    private Enumeration customerCategory; //客户类别

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "shipment_conditions", referencedColumnName = "id")
    @Comment("装运条件编码")
    private Enumeration shipmentConditions; //装运条件

    @Column(name = "delivery_place", length = 500)
    @Comment("交货地点")
    private String deliveryPlace; //交货地点

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "customer_credit_group", referencedColumnName = "id")
    @Comment("客户信用组编码")
    private Enumeration customerCreditGroup; //客户信用组编码(customerCreditGroup)

    @Column(name = "is_want_invoice", nullable = false)
    @Comment("采购需要发票")
    private boolean isWantInvoice; //是否要发票

    @Column(name = "is_can_invoice", nullable = false,columnDefinition = "number(1,0) default 0")
    @Comment("能否开增值税发票")
    private boolean canInvoice = false;
    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("有效")
    private boolean valid = true; //有效

    @Column(name = "state", length = 16)
    @Comment("状态")
    private String state;   //状态

    @Column(name = "representative")
    @Comment("法人代表")
    private String representative;   //法人代表


    @Column(name = "contacts")
    @Comment("联系人")
    private String contacts;   //联系人

    @Column(name = "contacts_number")
    @Comment("联系人")
    private String contactsNumber;   //联系人电话

    @Column(name = "phone_number")
    @Comment("手机号码")
    private String phoneNumber;   //手机号码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "access_provider", referencedColumnName = "id")
    @Comment("接入商")
    private AccessProvider accessProvider;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "purchase_invoice", referencedColumnName = "id")
    @Comment("默认采购发票设置")
    private Enumeration purchaseInvoice; //默认采购发票设置(purchaseInvoice)

    @Column(name = "use", columnDefinition = "number(1,0) default 1")
    @Comment("是否使用新框架")
    private boolean use = true;


    @File
    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "LOGO",columnDefinition = "CLOB")
    @Comment("LOGO")
    private String logo;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "taxpayer_id", referencedColumnName = "id")
    @Comment("纳税人")
    private Enumeration taxpayer;

    @Column(name = "operator_sign", columnDefinition = "number(1,0) default 0")
    @Comment("运营商标记")
    private boolean operatorSign = false;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "belong_operator", referencedColumnName = "id")
    @Comment("所属运营商")
    private PartyRole belongOperator;
}
